#!/bin/bash
OK=0
WARN=1
CRITICAL=2
UNKNOWN=3
PATH="/bin:/sbin:/usr/bin:/usr/sbin"
HName=`/bin/hostname -s`

Ok_name=''
Fail_name=''
Judge=0
TTimeout=10
check_dir='/beamlinefs /hepshome /hepsdatafs'
filename='nmswritetest/checktest.txt'

function timeout_write() {
    #echo $choice start
    /usr/bin/timeout $TTimeout /bin/strace touch /$1/$filename 1>/dev/null 2>&1
    /usr/bin/timeout $TTimeout /bin/strace rm -f /$1/$filename 1>/dev/null 2>&1
    #/usr/bin/timeout $TTimeout /bin/strace /bin/lfs df -h /$1  1>/dev/null 2>&1
    #/usr/bin/timeout $TTimeout /bin/strace /usr/bin/df -h /$1  1>/dev/null 2>&1
    if [ $? != 0  ]
        then
        Judge=1
        Fail_name="${Fail_name} $1"
    else
        Ok_name="${Ok_name} $1"
    fi
        #echo $choice end
}

for choice in $check_dir
do
        timeout_write $choice
done

if [ $Judge -eq 1 ]
then
        echo "$HName $Fail_name  write_timeout after $TTimeout wrong"
        exit $CRITICAL
else
        echo "$HName $Ok_name  write_time are in $TTimeout OK "
        exit $OK
fi

